package com.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.mapper.Wms_Ware_Info_Mapper;
import com.shop.pojo.wms.Wms_Ware_Info;
import com.shop.service.Wms_Ware_Info_Service;
import com.shop.utils.LayuiUtils;
import com.shop.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 后台仓库信息-李贝贝
 */
@Service
public class Wms_Ware_Info_ServiceImpl implements Wms_Ware_Info_Service {

    @Autowired
    private Wms_Ware_Info_Mapper wms_ware_info_mapper;

    /**
     * 显示所有仓库
     * @param pages
     * @param wms_ware_info
     * @return
     */
    @Override
    public LayuiUtils<Wms_Ware_Info> find_admin_All_Ware(Page<Wms_Ware_Info> pages, Wms_Ware_Info wms_ware_info) {
        LayuiUtils<Wms_Ware_Info> layuis = new LayuiUtils<>();
        QueryWrapper<Wms_Ware_Info> query = new QueryWrapper<>();
        if (wms_ware_info.getName() != null) {
            query.like("name", wms_ware_info.getName());
        }

        Page<Wms_Ware_Info> wms_ware_infoPage = wms_ware_info_mapper.selectPage(pages, query);
        layuis.setCount(wms_ware_infoPage.getTotal());
        layuis.setData(wms_ware_infoPage.getRecords());
        return layuis;
    }

    /**
     * 添加仓库
     * @param wms_ware_info
     * @return
     */
    @Override
    public R insert_admin_ware(Wms_Ware_Info wms_ware_info) {
        int insert = wms_ware_info_mapper.insert(wms_ware_info);
        if(insert > 0){
            return R.success();
        }
        return R.error(500,"添加失败");
    }

    /**
     * 删除仓库
     * @param id
     * @return
     */
    @Override
    public R delete_admin_ware(List<Long> id) {
        int ids = wms_ware_info_mapper.deleteBatchIds(id);
        if(ids > 0){
            return R.success();
        }else {
            return R.error(500,"删除失败");
        }
    }

    /**
     * 修改仓库
     * @param wms_ware_info
     * @return
     */
    @Override
    public R update_admin_ware(Wms_Ware_Info wms_ware_info) {



       int o = wms_ware_info_mapper.updateById(wms_ware_info);
       if(o > 0){
           return R.success();
       }else {
           return R.error(500,"修改失败");
       }
    }

}
